package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.ProCommunity;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-29
 * Time: 16:55
 *
 * @version 1.0
 */
public class ProCommunityMapperProvider {

    public String insertUserId() {
        return new SQL() {{
            INSERT_INTO("tbl_professional_community");
            VALUES("user_id", "#{userId}");
        }}.toString();
    }


//    public String insertOne() {
//        return new SQL() {{
//            INSERT_INTO("tbl_professional_community");
//            VALUES("user_id", "#{userId}");
//            VALUES("github_url", "#{githubUrl}");
//            VALUES("know_url", "#{knowUrl}");
//            VALUES("stackoverflow_url", "#{stackoverflowUrl}");
//            VALUES("dribbble_url", "#{dribbbleUrl}");
//            VALUES("create_time", "#{createTime}");
//        }}.toString();
//    }


//    public String deleteOneById() {
//        return new SQL() {{
//            UPDATE("tbl_professional_community");
//            SET("is_deleted=1");
//            WHERE("id=#{id}");
//        }}.toString();
//    }


    public String updateOne(ProCommunity proCommunity) {
        return new SQL() {{
            UPDATE("tbl_professional_community");
            if (!EmptyUtil.isEmpty(proCommunity.getGithubUrl())) {
                SET("github_url=#{githubUrl}");
            }
            if (!EmptyUtil.isEmpty(proCommunity.getKnowUrl())) {
                SET("know_url=#{knowUrl}");
            }
            if (!EmptyUtil.isEmpty(proCommunity.getStackoverflowUrl())) {
                SET("stackoverflow_url=#{stackoverflowUrl}");
            }
            if (!EmptyUtil.isEmpty(proCommunity.getDribbbleUrl())) {
                SET("dribbble_url=#{dribbbleUrl}");
            }
            WHERE("user_id=#{userId}");

        }}.toString();

    }

    public String getOne() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_professional_community");
            WHERE("is_deleted=0 AND user_id=#{userId}");
        }}.toString();
    }

}
